
## Common information to several classes.
##    
## Should not be directly used, several classes are derived from
## this one.    
class Base(object):
    def __init__(self):
        self.__attributes = {}
        self.__type = 'None'
        self.__parentGraph = None
        self.__validAttributes = None
    
    ## Look for default attributes for this node    
    def __getDefaultAttributeValue(self, inAttr):
        attributeValue = self.__attributes.get(inAttr, None)
        
        if attributeValue is None:
            # get the defaults for nodes/edges
            defaultNodeName = self.__type
            
            # The defaults for graphs are set on a node named 'graph'
            if defaultNodeName in ('subgraph', 'digraph', 'cluster'):
                defaultNodeName = 'graph'
                
            defaults = self.getParentGraph().getNode( defaultNodeName )
            if defaults:
                attributeValue = defaults.getAttributes().get(inAttr, None)
                
        return attributeValue

    def setParentGraph(self, inParentGraph):
        self.__parentGraph = inParentGraph
        
    def getParentGraph(self):
        return self.__parentGraph

    def isValidAttribute(self, inAttributeName):
        return hasattr(self, inAttributeName)
        
    ## Set an attribute value by name.
    def setAttribute(self, inAttributeName, inAttributeValue):
        if self.isValidAttribute(inAttributeName):
            self.__attributes[inAttributeName] = inAttributeValue
        else:
            raise PyGraphError, '%s is not a valid attributes for %s' %(inAttributeName, self.__type)

    ## Get an attribute value by name.
    def getAttribute(self, inAttributeName):
        retAttribute = None
        if self.isValidAttribute(inAttributeName):
            if self.__attributes.has_key(inAttributeName):
                retAttribute = self.__attributes[inAttributeName]
        else:
            raise PyGraphError, '%s is not a valid attributes for %s' %(inAttributeName, self.__type)
        
        return retAttribute

    def getPossibleAttributes(self):
        possibleAttrs = ''
        for attr in 
    def getDefinedAttributes(self):
        return copy.copy(self.__attributes)

        
    def set_sequence(self, seq):
    
        self.obj_dict['sequence'] = seq


    def get_sequence(self):
    
        return self.obj_dict['sequence']
        
        
    def create_attribute_methods(self, obj_attributes):
    
        #for attr in self.obj_dict['attributes']:
        for attr in obj_attributes:
        
            # Generate all the Setter methods.
            #
            self.__setattr__( 'set_'+attr, lambda x, a=attr : self.obj_dict['attributes'].__setitem__(a, x) )
            
            # Generate all the Getter methods.
            #
            self.__setattr__('get_'+attr, lambda a=attr : self.__get_attribute__(a))

